# 向社区仓库上传文件
import os

def upload(path):
    from modelfoundry_hub import MdsApi
    token = ""
    api = MdsApi(token=token, endpoint="https://giteash.test.osinfra.cn")

    if not os.path.exists(path):
        raise ValueError(f"{path} is not found!")

    if os.path.isfile(path, repo_id):
        file = path
        file_name = os.path.basename(file)
        api.upload_file(path_or_fileobj=file, repo_id=repo_id, path_in_repo=file_name)
    else:
        file_list = os.listdir(path)
        for file_name in file_list:
            file = os.path.join(path, file_name)
            api.upload_file(path_or_fileobj=file, repo_id=repo_id, path_in_repo=file_name)

    # create_repo("llama_7b", token=token)

if __name__ == '__main__':
    path = ""
    repo_id = ""
    upload(path, repo_id)